package com.dindang.ddm.app.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.dindang.ddm.mvp.model.entity.MainEvent;
import com.jess.arms.utils.ArmsUtils;

import org.greenrobot.eventbus.EventBus;

public class NetworkConnectChangedReceiver  extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getActiveNetworkInfo();
        if(networkInfo!=null&&networkInfo.isConnected()){
            //监听网络的变化，这里进行缓存上传
            MainEvent mainEvent = new MainEvent();
            EventBus.getDefault().post(mainEvent);
//            ArmsUtils.makeText(context,"网络连接成功了哇");
        }else{
//            ArmsUtils.makeText(context,"网络连接失败了哇");
        }
    }
}
